package com.dude.screens;

import com.dude.R;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioGroup;

/**
 * settings screen
 * IMPORTANT - this screen can be called from the main screen using the menu button on the phone/emulator 
 */
public class Settings extends Activity
{
	// ====================== global variables ==============================
	// the path where the shared preferences are saved
	public static final String settings = "pref_file";
	
	// ====================== global variables ==============================
	// the names of the preferences in the application
	public static final String useCamera = "use_camera";	
	public static final String useSoundPref = "use_sound";
	public static final String useVoicePref = "use_voice";
	
	// ======================================================================
	
	private CheckBox useCameraCheckBox;
	private CheckBox useSound;
	private CheckBox useVoice;

	// ======================================================================
	@Override
    public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		
		SharedPreferences settings = getSharedPreferences(Settings.settings, 0);
		final SharedPreferences.Editor editor = settings.edit();
		
		useCameraCheckBox = (CheckBox) findViewById(R.id.use_camera_checkbox);
		useCameraCheckBox.setChecked(settings.getBoolean(useCamera, false));		//TODO after debugging make default true
		useCameraCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
			@Override
			public void onCheckedChanged(CompoundButton buttonView,	boolean isChecked) 
			{
				if (isChecked){
					editor.putBoolean(useCamera, true);
				}
				else{
					editor.putBoolean(useCamera, false); 
				}
				editor.commit();
			}
		});
		
		useSound = (CheckBox) findViewById(R.id.use_sound_checkbox);
		useSound.setChecked(settings.getBoolean(useSoundPref, true));
		useSound.setOnCheckedChangeListener(new OnCheckedChangeListener(){
			@Override
			public void onCheckedChanged(CompoundButton buttonView,	boolean isChecked) 
			{
				if (isChecked){
					editor.putBoolean(useSoundPref, true);
				}
				else{
					editor.putBoolean(useSoundPref, false); 
				}
				editor.commit();
			}
		});
		
		useVoice = (CheckBox) findViewById(R.id.use_voice_checkbox);
		useVoice.setChecked(settings.getBoolean(useVoicePref , false));
		useVoice.setOnCheckedChangeListener(new OnCheckedChangeListener(){
			@Override
			public void onCheckedChanged(CompoundButton buttonView,	boolean isChecked) 
			{
				if (isChecked){
					editor.putBoolean(useVoicePref, true);
				}
				else{
					editor.putBoolean(useVoicePref, false); 
				}
				editor.commit();
			}
		});
	}	
	
}
